package com.plr.booker.xml;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import org.example.message.CompanyNameType;
import org.example.message.OTAAirLowFareSearchRQElement;
import org.example.message.POSType;
import org.example.message.SourceType;
import org.example.message.SourceType.BookingChannel;
import org.example.message.SourceType.RequestorID;

public class Pizza {
	public static void main(String[] args) {

		OTAAirLowFareSearchRQElement lfsRQ = new OTAAirLowFareSearchRQElement();

		POSType pos = new POSType();

		// <POS>
		// <Source AgentDutyCode="0004113" AgentSine="cfal" ERSP_UserID="001"
		// ISOCountry="CA">
		// <RequestorID ID=" " Type="0.AAA.X">
		// <CompanyName Code="6af3abad" CodeContext="DC"
		// CompanyShortName="AirCanada" />
		// </RequestorID>
		// <BookingChannel Type="GDS">
		// <CompanyName Code="abc123" />
		// </BookingChannel>
		// </Source>
		// </POS>

		SourceType source = new SourceType();
		pos.getSource().add(source);

		source.setISOCountry("CA");
		source.setAgentDutyCode("0004113");
		source.setAgentSine("cfal");
		source.setERSPUserID("001");

		RequestorID requestorID = new RequestorID();

		source.setRequestorID(requestorID);

		requestorID.setID(" ");
		requestorID.setType("0.AAA.X");

		CompanyNameType companyName = new CompanyNameType();

		requestorID.setCompanyName(companyName);

		companyName.setCode("6af3abad");
		companyName.setCodeContext("DC");
		companyName.setCompanyShortName("AirCanada");

		pos.getSource();

		BookingChannel bookingChannel = new BookingChannel();

		bookingChannel.setType("GDS");
		source.setBookingChannel(bookingChannel);

		companyName = new CompanyNameType();
		bookingChannel.setCompanyName(companyName);
		companyName.setCode("abc123");
		lfsRQ.setPOS(pos);

		try {
			JAXBContext jaxbContext = JAXBContext
					.newInstance(OTAAirLowFareSearchRQElement.class);

			Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

			// output pretty printed
			jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

			jaxbMarshaller.marshal(lfsRQ, System.out);

		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
